// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_double_from_datetimev2_3_part9") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_double_from_datetimev2_3_part9_9_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_3_part9_9_nullable(f1 int, f2 datetimev2(3)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_3_part9_9_nullable values (0, "9999-01-28 23:00:00.000"),(1, "9999-01-28 23:00:00.000"),(2, "9999-01-28 23:00:00.999"),(3, "9999-01-28 23:00:01.000"),(4, "9999-01-28 23:00:01.000"),(5, "9999-01-28 23:00:01.999"),(6, "9999-01-28 23:00:59.000"),(7, "9999-01-28 23:00:59.000"),(8, "9999-01-28 23:00:59.999"),(9, "9999-01-28 23:01:00.000"),(10, "9999-01-28 23:01:00.000"),(11, "9999-01-28 23:01:00.999"),(12, "9999-01-28 23:01:01.000"),(13, "9999-01-28 23:01:01.000"),(14, "9999-01-28 23:01:01.999"),(15, "9999-01-28 23:01:59.000"),(16, "9999-01-28 23:01:59.000"),(17, "9999-01-28 23:01:59.999"),(18, "9999-01-28 23:59:00.000"),(19, "9999-01-28 23:59:00.000"),
      (20, "9999-01-28 23:59:00.999"),(21, "9999-01-28 23:59:01.000"),(22, "9999-01-28 23:59:01.000"),(23, "9999-01-28 23:59:01.999"),(24, "9999-01-28 23:59:59.000"),(25, "9999-01-28 23:59:59.000"),(26, "9999-01-28 23:59:59.999"),(27, "9999-12-01 00:00:00.000"),(28, "9999-12-01 00:00:00.000"),(29, "9999-12-01 00:00:00.999"),(30, "9999-12-01 00:00:01.000"),(31, "9999-12-01 00:00:01.000"),(32, "9999-12-01 00:00:01.999"),(33, "9999-12-01 00:00:59.000"),(34, "9999-12-01 00:00:59.000"),(35, "9999-12-01 00:00:59.999"),(36, "9999-12-01 00:01:00.000"),(37, "9999-12-01 00:01:00.000"),(38, "9999-12-01 00:01:00.999"),(39, "9999-12-01 00:01:01.000"),
      (40, "9999-12-01 00:01:01.000"),(41, "9999-12-01 00:01:01.999"),(42, "9999-12-01 00:01:59.000"),(43, "9999-12-01 00:01:59.000"),(44, "9999-12-01 00:01:59.999"),(45, "9999-12-01 00:59:00.000"),(46, "9999-12-01 00:59:00.000"),(47, "9999-12-01 00:59:00.999"),(48, "9999-12-01 00:59:01.000"),(49, "9999-12-01 00:59:01.000"),(50, "9999-12-01 00:59:01.999"),(51, "9999-12-01 00:59:59.000"),(52, "9999-12-01 00:59:59.000"),(53, "9999-12-01 00:59:59.999"),(54, "9999-12-01 01:00:00.000"),(55, "9999-12-01 01:00:00.000"),(56, "9999-12-01 01:00:00.999"),(57, "9999-12-01 01:00:01.000"),(58, "9999-12-01 01:00:01.000"),(59, "9999-12-01 01:00:01.999"),
      (60, "9999-12-01 01:00:59.000"),(61, "9999-12-01 01:00:59.000"),(62, "9999-12-01 01:00:59.999"),(63, "9999-12-01 01:01:00.000"),(64, "9999-12-01 01:01:00.000"),(65, "9999-12-01 01:01:00.999"),(66, "9999-12-01 01:01:01.000"),(67, "9999-12-01 01:01:01.000"),(68, "9999-12-01 01:01:01.999"),(69, "9999-12-01 01:01:59.000"),(70, "9999-12-01 01:01:59.000"),(71, "9999-12-01 01:01:59.999"),(72, "9999-12-01 01:59:00.000"),(73, "9999-12-01 01:59:00.000"),(74, "9999-12-01 01:59:00.999"),(75, "9999-12-01 01:59:01.000"),(76, "9999-12-01 01:59:01.000"),(77, "9999-12-01 01:59:01.999"),(78, "9999-12-01 01:59:59.000"),(79, "9999-12-01 01:59:59.000"),
      (80, "9999-12-01 01:59:59.999"),(81, "9999-12-01 23:00:00.000"),(82, "9999-12-01 23:00:00.000"),(83, "9999-12-01 23:00:00.999"),(84, "9999-12-01 23:00:01.000"),(85, "9999-12-01 23:00:01.000"),(86, "9999-12-01 23:00:01.999"),(87, "9999-12-01 23:00:59.000"),(88, "9999-12-01 23:00:59.000"),(89, "9999-12-01 23:00:59.999"),(90, "9999-12-01 23:01:00.000"),(91, "9999-12-01 23:01:00.000"),(92, "9999-12-01 23:01:00.999"),(93, "9999-12-01 23:01:01.000"),(94, "9999-12-01 23:01:01.000"),(95, "9999-12-01 23:01:01.999"),(96, "9999-12-01 23:01:59.000"),(97, "9999-12-01 23:01:59.000"),(98, "9999-12-01 23:01:59.999"),(99, "9999-12-01 23:59:00.000"),
      (100, "9999-12-01 23:59:00.000"),(101, "9999-12-01 23:59:00.999"),(102, "9999-12-01 23:59:01.000"),(103, "9999-12-01 23:59:01.000"),(104, "9999-12-01 23:59:01.999"),(105, "9999-12-01 23:59:59.000"),(106, "9999-12-01 23:59:59.000"),(107, "9999-12-01 23:59:59.999"),(108, "9999-12-28 00:00:00.000"),(109, "9999-12-28 00:00:00.000"),(110, "9999-12-28 00:00:00.999"),(111, "9999-12-28 00:00:01.000"),(112, "9999-12-28 00:00:01.000"),(113, "9999-12-28 00:00:01.999"),(114, "9999-12-28 00:00:59.000"),(115, "9999-12-28 00:00:59.000"),(116, "9999-12-28 00:00:59.999"),(117, "9999-12-28 00:01:00.000"),(118, "9999-12-28 00:01:00.000"),(119, "9999-12-28 00:01:00.999"),
      (120, "9999-12-28 00:01:01.000"),(121, "9999-12-28 00:01:01.000"),(122, "9999-12-28 00:01:01.999"),(123, "9999-12-28 00:01:59.000"),(124, "9999-12-28 00:01:59.000"),(125, "9999-12-28 00:01:59.999"),(126, "9999-12-28 00:59:00.000"),(127, "9999-12-28 00:59:00.000"),(128, "9999-12-28 00:59:00.999"),(129, "9999-12-28 00:59:01.000"),(130, "9999-12-28 00:59:01.000"),(131, "9999-12-28 00:59:01.999"),(132, "9999-12-28 00:59:59.000"),(133, "9999-12-28 00:59:59.000"),(134, "9999-12-28 00:59:59.999"),(135, "9999-12-28 01:00:00.000"),(136, "9999-12-28 01:00:00.000"),(137, "9999-12-28 01:00:00.999"),(138, "9999-12-28 01:00:01.000"),(139, "9999-12-28 01:00:01.000"),
      (140, "9999-12-28 01:00:01.999"),(141, "9999-12-28 01:00:59.000"),(142, "9999-12-28 01:00:59.000"),(143, "9999-12-28 01:00:59.999"),(144, "9999-12-28 01:01:00.000"),(145, "9999-12-28 01:01:00.000"),(146, "9999-12-28 01:01:00.999"),(147, "9999-12-28 01:01:01.000"),(148, "9999-12-28 01:01:01.000"),(149, "9999-12-28 01:01:01.999"),(150, "9999-12-28 01:01:59.000"),(151, "9999-12-28 01:01:59.000"),(152, "9999-12-28 01:01:59.999"),(153, "9999-12-28 01:59:00.000"),(154, "9999-12-28 01:59:00.000"),(155, "9999-12-28 01:59:00.999"),(156, "9999-12-28 01:59:01.000"),(157, "9999-12-28 01:59:01.000"),(158, "9999-12-28 01:59:01.999"),(159, "9999-12-28 01:59:59.000"),
      (160, "9999-12-28 01:59:59.000"),(161, "9999-12-28 01:59:59.999"),(162, "9999-12-28 23:00:00.000"),(163, "9999-12-28 23:00:00.000"),(164, "9999-12-28 23:00:00.999"),(165, "9999-12-28 23:00:01.000"),(166, "9999-12-28 23:00:01.000"),(167, "9999-12-28 23:00:01.999"),(168, "9999-12-28 23:00:59.000"),(169, "9999-12-28 23:00:59.000"),(170, "9999-12-28 23:00:59.999"),(171, "9999-12-28 23:01:00.000"),(172, "9999-12-28 23:01:00.000"),(173, "9999-12-28 23:01:00.999"),(174, "9999-12-28 23:01:01.000"),(175, "9999-12-28 23:01:01.000"),(176, "9999-12-28 23:01:01.999"),(177, "9999-12-28 23:01:59.000"),(178, "9999-12-28 23:01:59.000"),(179, "9999-12-28 23:01:59.999"),
      (180, "9999-12-28 23:59:00.000"),(181, "9999-12-28 23:59:00.000"),(182, "9999-12-28 23:59:00.999"),(183, "9999-12-28 23:59:01.000"),(184, "9999-12-28 23:59:01.000"),(185, "9999-12-28 23:59:01.999"),(186, "9999-12-28 23:59:59.000"),(187, "9999-12-28 23:59:59.000"),(188, "9999-12-28 23:59:59.999")
      ,(189, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_3_part9_9_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_9_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_3_part9_9_nullable order by 1;'

    sql "drop table if exists test_cast_to_double_from_datetimev2_3_part9_9_not_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_3_part9_9_not_nullable(f1 int, f2 datetimev2(3)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_3_part9_9_not_nullable values (0, "9999-01-28 23:00:00.000"),(1, "9999-01-28 23:00:00.000"),(2, "9999-01-28 23:00:00.999"),(3, "9999-01-28 23:00:01.000"),(4, "9999-01-28 23:00:01.000"),(5, "9999-01-28 23:00:01.999"),(6, "9999-01-28 23:00:59.000"),(7, "9999-01-28 23:00:59.000"),(8, "9999-01-28 23:00:59.999"),(9, "9999-01-28 23:01:00.000"),(10, "9999-01-28 23:01:00.000"),(11, "9999-01-28 23:01:00.999"),(12, "9999-01-28 23:01:01.000"),(13, "9999-01-28 23:01:01.000"),(14, "9999-01-28 23:01:01.999"),(15, "9999-01-28 23:01:59.000"),(16, "9999-01-28 23:01:59.000"),(17, "9999-01-28 23:01:59.999"),(18, "9999-01-28 23:59:00.000"),(19, "9999-01-28 23:59:00.000"),
      (20, "9999-01-28 23:59:00.999"),(21, "9999-01-28 23:59:01.000"),(22, "9999-01-28 23:59:01.000"),(23, "9999-01-28 23:59:01.999"),(24, "9999-01-28 23:59:59.000"),(25, "9999-01-28 23:59:59.000"),(26, "9999-01-28 23:59:59.999"),(27, "9999-12-01 00:00:00.000"),(28, "9999-12-01 00:00:00.000"),(29, "9999-12-01 00:00:00.999"),(30, "9999-12-01 00:00:01.000"),(31, "9999-12-01 00:00:01.000"),(32, "9999-12-01 00:00:01.999"),(33, "9999-12-01 00:00:59.000"),(34, "9999-12-01 00:00:59.000"),(35, "9999-12-01 00:00:59.999"),(36, "9999-12-01 00:01:00.000"),(37, "9999-12-01 00:01:00.000"),(38, "9999-12-01 00:01:00.999"),(39, "9999-12-01 00:01:01.000"),
      (40, "9999-12-01 00:01:01.000"),(41, "9999-12-01 00:01:01.999"),(42, "9999-12-01 00:01:59.000"),(43, "9999-12-01 00:01:59.000"),(44, "9999-12-01 00:01:59.999"),(45, "9999-12-01 00:59:00.000"),(46, "9999-12-01 00:59:00.000"),(47, "9999-12-01 00:59:00.999"),(48, "9999-12-01 00:59:01.000"),(49, "9999-12-01 00:59:01.000"),(50, "9999-12-01 00:59:01.999"),(51, "9999-12-01 00:59:59.000"),(52, "9999-12-01 00:59:59.000"),(53, "9999-12-01 00:59:59.999"),(54, "9999-12-01 01:00:00.000"),(55, "9999-12-01 01:00:00.000"),(56, "9999-12-01 01:00:00.999"),(57, "9999-12-01 01:00:01.000"),(58, "9999-12-01 01:00:01.000"),(59, "9999-12-01 01:00:01.999"),
      (60, "9999-12-01 01:00:59.000"),(61, "9999-12-01 01:00:59.000"),(62, "9999-12-01 01:00:59.999"),(63, "9999-12-01 01:01:00.000"),(64, "9999-12-01 01:01:00.000"),(65, "9999-12-01 01:01:00.999"),(66, "9999-12-01 01:01:01.000"),(67, "9999-12-01 01:01:01.000"),(68, "9999-12-01 01:01:01.999"),(69, "9999-12-01 01:01:59.000"),(70, "9999-12-01 01:01:59.000"),(71, "9999-12-01 01:01:59.999"),(72, "9999-12-01 01:59:00.000"),(73, "9999-12-01 01:59:00.000"),(74, "9999-12-01 01:59:00.999"),(75, "9999-12-01 01:59:01.000"),(76, "9999-12-01 01:59:01.000"),(77, "9999-12-01 01:59:01.999"),(78, "9999-12-01 01:59:59.000"),(79, "9999-12-01 01:59:59.000"),
      (80, "9999-12-01 01:59:59.999"),(81, "9999-12-01 23:00:00.000"),(82, "9999-12-01 23:00:00.000"),(83, "9999-12-01 23:00:00.999"),(84, "9999-12-01 23:00:01.000"),(85, "9999-12-01 23:00:01.000"),(86, "9999-12-01 23:00:01.999"),(87, "9999-12-01 23:00:59.000"),(88, "9999-12-01 23:00:59.000"),(89, "9999-12-01 23:00:59.999"),(90, "9999-12-01 23:01:00.000"),(91, "9999-12-01 23:01:00.000"),(92, "9999-12-01 23:01:00.999"),(93, "9999-12-01 23:01:01.000"),(94, "9999-12-01 23:01:01.000"),(95, "9999-12-01 23:01:01.999"),(96, "9999-12-01 23:01:59.000"),(97, "9999-12-01 23:01:59.000"),(98, "9999-12-01 23:01:59.999"),(99, "9999-12-01 23:59:00.000"),
      (100, "9999-12-01 23:59:00.000"),(101, "9999-12-01 23:59:00.999"),(102, "9999-12-01 23:59:01.000"),(103, "9999-12-01 23:59:01.000"),(104, "9999-12-01 23:59:01.999"),(105, "9999-12-01 23:59:59.000"),(106, "9999-12-01 23:59:59.000"),(107, "9999-12-01 23:59:59.999"),(108, "9999-12-28 00:00:00.000"),(109, "9999-12-28 00:00:00.000"),(110, "9999-12-28 00:00:00.999"),(111, "9999-12-28 00:00:01.000"),(112, "9999-12-28 00:00:01.000"),(113, "9999-12-28 00:00:01.999"),(114, "9999-12-28 00:00:59.000"),(115, "9999-12-28 00:00:59.000"),(116, "9999-12-28 00:00:59.999"),(117, "9999-12-28 00:01:00.000"),(118, "9999-12-28 00:01:00.000"),(119, "9999-12-28 00:01:00.999"),
      (120, "9999-12-28 00:01:01.000"),(121, "9999-12-28 00:01:01.000"),(122, "9999-12-28 00:01:01.999"),(123, "9999-12-28 00:01:59.000"),(124, "9999-12-28 00:01:59.000"),(125, "9999-12-28 00:01:59.999"),(126, "9999-12-28 00:59:00.000"),(127, "9999-12-28 00:59:00.000"),(128, "9999-12-28 00:59:00.999"),(129, "9999-12-28 00:59:01.000"),(130, "9999-12-28 00:59:01.000"),(131, "9999-12-28 00:59:01.999"),(132, "9999-12-28 00:59:59.000"),(133, "9999-12-28 00:59:59.000"),(134, "9999-12-28 00:59:59.999"),(135, "9999-12-28 01:00:00.000"),(136, "9999-12-28 01:00:00.000"),(137, "9999-12-28 01:00:00.999"),(138, "9999-12-28 01:00:01.000"),(139, "9999-12-28 01:00:01.000"),
      (140, "9999-12-28 01:00:01.999"),(141, "9999-12-28 01:00:59.000"),(142, "9999-12-28 01:00:59.000"),(143, "9999-12-28 01:00:59.999"),(144, "9999-12-28 01:01:00.000"),(145, "9999-12-28 01:01:00.000"),(146, "9999-12-28 01:01:00.999"),(147, "9999-12-28 01:01:01.000"),(148, "9999-12-28 01:01:01.000"),(149, "9999-12-28 01:01:01.999"),(150, "9999-12-28 01:01:59.000"),(151, "9999-12-28 01:01:59.000"),(152, "9999-12-28 01:01:59.999"),(153, "9999-12-28 01:59:00.000"),(154, "9999-12-28 01:59:00.000"),(155, "9999-12-28 01:59:00.999"),(156, "9999-12-28 01:59:01.000"),(157, "9999-12-28 01:59:01.000"),(158, "9999-12-28 01:59:01.999"),(159, "9999-12-28 01:59:59.000"),
      (160, "9999-12-28 01:59:59.000"),(161, "9999-12-28 01:59:59.999"),(162, "9999-12-28 23:00:00.000"),(163, "9999-12-28 23:00:00.000"),(164, "9999-12-28 23:00:00.999"),(165, "9999-12-28 23:00:01.000"),(166, "9999-12-28 23:00:01.000"),(167, "9999-12-28 23:00:01.999"),(168, "9999-12-28 23:00:59.000"),(169, "9999-12-28 23:00:59.000"),(170, "9999-12-28 23:00:59.999"),(171, "9999-12-28 23:01:00.000"),(172, "9999-12-28 23:01:00.000"),(173, "9999-12-28 23:01:00.999"),(174, "9999-12-28 23:01:01.000"),(175, "9999-12-28 23:01:01.000"),(176, "9999-12-28 23:01:01.999"),(177, "9999-12-28 23:01:59.000"),(178, "9999-12-28 23:01:59.000"),(179, "9999-12-28 23:01:59.999"),
      (180, "9999-12-28 23:59:00.000"),(181, "9999-12-28 23:59:00.000"),(182, "9999-12-28 23:59:00.999"),(183, "9999-12-28 23:59:01.000"),(184, "9999-12-28 23:59:01.000"),(185, "9999-12-28 23:59:01.999"),(186, "9999-12-28 23:59:59.000"),(187, "9999-12-28 23:59:59.000"),(188, "9999-12-28 23:59:59.999");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_3_part9_9_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_9_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_3_part9_9_not_nullable order by 1;'

}